Completed
Push — master ( 2281e8...8b163e )
by Justin
01:35
created

GDate.getOriginal   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
var ExtensibleData = require('./ExtensibleData'),
2
    utils = require('./utils');
3
4
/**
5
 * A date.
6
 * 
7
 * @constructor
8
 * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
9
 * @alias Date
10
 */
11
var GDate = function(json){
12
  
13
  // Protect against forgetting the new keyword when calling the constructor
14
  if(!(this instanceof GDate)){
15
    return new GDate(json);
16
  }
17
  
18
  // If the given object is already an instance then just return it. DON'T copy it.
19
  if(GDate.isInstance(json)){
20
    return json;
21
  }
22
  
23
  ExtensibleData.call(this, json);
24
  
25
  if(json){
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if json is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
26
    this.setOriginal(json.original);
27
    this.setFormal(json.formal);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
28
  }
29
};
30
31
GDate.prototype = Object.create(ExtensibleData.prototype);
32
33
GDate._gedxClass = GDate.prototype._gedxClass = 'GedcomX.Date';
34
35
/**
36
 * Check whether the given object is an instance of this class.
37
 * 
38
 * @param {Object} obj
39
 * @returns {Boolean}
40
 */
41
GDate.isInstance = function(obj){
42
  return utils.isInstance(obj, this._gedxClass);
43
};
44
45
/**
46
 * Get the original date value
47
 * 
48
 * @returns {String} original
49
 */
50
GDate.prototype.getOriginal = function(){
51
  return this.original;
52
};
53
54
/**
55
 * Set the original date value
56
 * 
57
 * @param {String} original
58
 * @returns {Date} This instance.
59
 */
60
GDate.prototype.setOriginal = function(original){
61
  this.original = original;
62
  return this;
63
};
64
65
/**
66
 * Get the formal date value
67
 * 
68
 * @returns {String}
69
 */
70
GDate.prototype.getFormal = function(){
71
  return this.formal;
72
};
73
74
/**
75
 * Set the formal date value
76
 * 
77
 * @param {String} formal
78
 * @returns {Date} This instance.
79
 */
80
GDate.prototype.setFormal = function(formal){
81
  this.formal = formal;
82
  return this;
83
};
84
85
/**
86
 * Export the object as JSON
87
 * 
88
 * @return {Object} JSON object
89
 */
90
GDate.prototype.toJSON = function(){
91
  var json = ExtensibleData.prototype.toJSON.call(this);
92
  
93
  if(this.original){
94
    json.original = this.original;
95
  }
96
  
97
  if(this.formal){
98
    json.formal = this.formal;
99
  }
100
  
101
  return json;
102
};
103
104
module.exports = GDate;